using Unity.VisualScripting;
using GameFramework;
using GameFramework.Download;

namespace LS.UGFUnits
{
    [UnitSurtitle("Download")]
    [UnitShortTitle("Get Info")]
    public sealed class GetDownloadInfo : DownloadUnit
    {
        [DoNotSerialize]
        [PortLabelHidden]
        public ValueInput SerialId { get; private set; }

        [DoNotSerialize]
        [PortLabelHidden]
        public ValueOutput Info { get; private set; }

        protected override void Definition()
        {
            SerialId = ValueInput<int>(nameof(SerialId));
            Info = ValueOutput<TaskInfo>(nameof(TaskInfo));
            Requirement(SerialId, Input);
        }
        protected override ControlOutput In(Flow flow)
        {
            int serialId = flow.GetValue<int>(SerialId);
            TaskInfo info = Target?.GetDownloadInfo(serialId) ?? default(TaskInfo);
            flow.SetValue(Info, info);
            return base.In(flow);
        }
    }
}